<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";

import { txjl, tgyDetails3, txsh } from "@/http/api";

export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "待审核", value: "1" },
        { label: "已通过", value: "2" },
        { label: "已驳回", value: "3" },
      ],
      showMoneyDetail: false,
      queryData: {
        status: "",
        withdrawal_number: "",
        tgy_name: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    questCheck(data) {
      txsh(data).then((res) => {
        if (res.data.code == 1) {
          ElMessage({
            type: "success",
            message: "操作成功",
          });
          this.getData();
        }
      });
    },
    checkStatus(row, type) {
      if (type == 2) {
        ElMessageBox.confirm(
          "确定通过选择的佣金提现申请吗?通过后微信将自动打款，请谨慎操作认真核对。",
          "操作提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        ).then(() => {
          let data = {
            withdrawal_id: row.withdrawal_id,
            status: type,
          };
          this.questCheck(data);
        });
      } else {
        ElMessageBox.prompt("确定驳回选择的佣金提现申请吗?", "操作提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then((value) => {
          let data = {
            withdrawal_id: row.withdrawal_id,
            status: type,
            bh_reason: value.value,
          };
          this.questCheck(data);
        });
      }
    },
    getMoneyDetail(item) {
      let data = {
        page: 1,
        per_page: 10,
        withdrawal_id: item.withdrawal_id,
      };
      tgyDetails3(data).then((res) => {
        if (res.data.code == 1) {
          this.gridData = res.data.data.data;
          this.showMoneyDetail = true;
        }
      });
    },
    getData() {
      this.queryData.account_id = this.$route.query.id || "";
      txjl(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {},
  created() {
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>佣金提现记录（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.withdrawal_number"
                placeholder="请输入订单号"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.tgy_name"
                placeholder="请输入推广员姓名"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.status"
                clearable
                @change="getData"
                placeholder="请选择状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="withdrawal_number"
          width="180"
          show-overflow-tooltip
          label="提现单号"
        />
        <el-table-column prop="tgy_name" show-overflow-tooltip label="姓名" />
        <el-table-column
          prop="tgy_mobile"
          show-overflow-tooltip
          width="150"
          label="手机号"
        />
        <el-table-column
          prop="commission"
          show-overflow-tooltip
          width="150"
          label="提现金额"
        />
        <el-table-column width="100" show-overflow-tooltip label="提现状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag v-if="row.status == 1">待审核</el-tag>
              <el-tag type="success" v-if="row.status == 2">已打款</el-tag>
              <el-tag type="danger" v-if="row.status == 3">已驳回</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="examine_time"
          width="180"
          show-overflow-tooltip
          label="审核时间"
        />
        <el-table-column
          prop="create_time"
          width="180"
          show-overflow-tooltip
          label="申请时间"
        />
        <el-table-column
          prop="bh_reason"
          show-overflow-tooltip
          label="驳回备注"
        />
        <el-table-column prop="Name" width="140" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="blueText ctrlText"
                v-if="row.status == 1"
                @click="checkStatus(row, 2)"
              >
                通过
              </div>
              <div
                class="redText ctrlText"
                v-if="row.status == 1"
                @click="checkStatus(row, 3)"
              >
                驳回
              </div>
              <div class="greenText ctrlText" @click="getMoneyDetail(row)">
                明细
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
      <el-dialog
        v-model="showMoneyDetail"
        align-center
        title="提现明细订单"
        width="1000"
      >
        <el-table :data="gridData">
          <el-table-column property="sign_number" label="订单号" />
          <el-table-column property="training_name" label="培训项目" />
          <el-table-column property="tg_commission" label="佣金金额" />
          <el-table-column
            width="170"
            property="create_time"
            label="创建时间"
          />
          <el-table-column
            width="170"
            property="complete_time"
            label="核销时间"
          />
          <el-table-column
            width="170"
            property="account_time"
            label="到账时间"
          />
        </el-table>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="showMoneyDetail = false">取消</el-button>
            <el-button type="primary" @click="showMoneyDetail = false">
              确定
            </el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
